
Product
Go Support Is Now Generally Available
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
dbgate-query-splitter
Advanced tools
Splits long SQL query into into particular statements. Designed to have zero dependencies and to be fast. Also supports nodejs-streams.
Supports following SQL dialects:
import {
splitQuery,
mysqlSplitterOptions,
mssqlSplitterOptions,
postgreSplitterOptions,
} from "dbgate-query-splitter";
const output = splitQuery(
"SELECT * FROM `table1`;SELECT * FROM `table2`;",
mysqlSplitterOptions
);
// output is ['SELECT * FROM `table1`', 'SELECT * FROM `table2`']
Function splitQueryStream accepts input stream and query options. Result is object stream, each object for one splitted query. From version 4.9.0, piping byline stream is not required.
const {
mysqlSplitterOptions,
mssqlSplitterOptions,
postgreSplitterOptions,
} = require("dbgate-query-splitter");
const {
splitQueryStream,
} = require("dbgate-query-splitter/lib/splitQueryStream");
const fs = require("fs");
const fileStream = fs.createReadStream("INPUT_FILE_NAME", "utf-8");
const splittedStream = splitQueryStream(fileStream, mysqlSplitterOptions);
By default, string array is returned. However, if you need to return row/column number information for splitted commands, use returnRichInfo option:
import { splitQuery, mysqlSplitterOptions } from "dbgate-query-splitter";
const output = splitQuery("SELECT * FROM `table1`;SELECT * FROM `table2`;", {
...mysqlSplitterOptions,
returnRichInfo: true,
});
Output is:
[
{
text: 'SELECT * FROM `table1`',
start: { position: 0, line: 0, column: 0 },
end: { position: 22, line: 0, column: 22 },
trimStart: { position: 0, line: 0, column: 0 },
trimEnd: { position: 22, line: 0, column: 22 }
},
{
text: 'SELECT * FROM `table2`',
start: { position: 23, line: 0, column: 23 },
end: { position: 46, line: 1, column: 22 },
trimStart: { position: 24, line: 1, column: 0 },
trimEnd: { position: 46, line: 1, column: 22 }
}
]
Please run tests before pushing any changes.
yarn test
FAQs
SQL Query splitter for verious database engines
The npm package dbgate-query-splitter receives a total of 1,140 weekly downloads. As such, dbgate-query-splitter popularity was classified as popular.
We found that dbgate-query-splitter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Go support is now generally available, bringing automatic scanning and deep code analysis to all users with Go projects.
Security News
vlt adds real-time security selectors powered by Socket, enabling developers to query and analyze package risks directly in their dependency graph.
Security News
CISA extended MITRE’s CVE contract by 11 months, avoiding a shutdown but leaving long-term governance and coordination issues unresolved.